package com.eascs.web.o2o.dc.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.StopWatch;
import com.eascs.web.o2o.dc.service.SynchroDataService;
import com.eascs.web.o2o.report.service.ProcessMonitorReportService;

/**
 * 同步   service业务系统数据
 * @author ycz
 *
 */
@Component("serviceTask")
public class ServiceTask {
	protected final Logger	logger	= LoggerFactory.getLogger(getClass());
	@Autowired
	ProcessMonitorReportService adapterDataReportService;
	@Autowired 
	private SynchroDataService synchroDataService;
	/**
	 * 同步业务系统数据--增量
	 * 1.贷前数据
	 * 2.贷中数据
	 * 3.贷后数据
	 */
	public void initData(){
		try {
			StopWatch stopWatch1=new StopWatch();
			logger.info("/****************开始同步贷前数据*****************************/");
			synchroDataService.synchroNew();
			logger.info("/****************同步贷前数据完成*****************************/");
			logger.info("贷前数据同步任务结束，共耗时：[{}]分", stopWatch1.elapsedTime() / 600000);
		} catch (Exception e) {
			logger.error("贷前数据同步异常：[{}]", e.getMessage());
		}
		
		try {
			StopWatch stopWatch2=new StopWatch();
			logger.info("/****************开始同步贷中数据*****************************/");
			synchroDataService.saveBaseO2oByLoading();
			logger.info("/****************同步贷中数据完成*****************************/");
			logger.info("贷中数据同步任务结束，共耗时：[{}]分", stopWatch2.elapsedTime() / 600000);
		} catch (Exception e) {
			logger.error("贷中数据同步异常：[{}]", e.getMessage());
		}
		try {
			StopWatch stopWatch3=new StopWatch();
			logger.info("/****************开始同步还款计划*****************************/");
			synchroDataService.savePaymentPlan();
			logger.info("/****************同步还款计划完成*****************************/");
			logger.info("还款计划同步任务结束，共耗时：[{}]分", stopWatch3.elapsedTime() / 60000);
		} catch (Exception e) {
			logger.error("还款计划数据同步异常：[{}]", e.getMessage());
		}
		try {
			StopWatch stopWatch3=new StopWatch();
			logger.info("/****************开始同步贷后数据*****************************/");
			synchroDataService.saveBaseO2oByAfter();
			logger.info("/****************同步贷后数据完成*****************************/");
			logger.info("贷后数据同步任务结束，共耗时：[{}]分", stopWatch3.elapsedTime() / 60000);
		} catch (Exception e) {
			logger.error("贷中数据同步异常：[{}]", e.getMessage());
		}
		
	}
	
	/**
	 * 同步还款计划--新系统
	 */
	public void sychroPaymentPlan(){
		synchroDataService.savePaymentPlan();
	}
	
}
